Skip to content

Conversation

@oltanik
Copy link

@oltanik oltanik commented Nov 29, 2023

No description provided.

# ???
count_student = {}
for student_dict in students:
for key, name in student_dict.items():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь не нужна итерация по словарю, можно же просто
name = student_dict['first_name']
остальное ок


counter_student_name_max = {}
for students_dict in students:
for key, name in students_dict.items():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

видимо эта ошибка идёт через все задания :)
это кстати именно ошибка, потому что может привести к неожиданному поведению, например если структура student_dict расширится вот таким образом

{'first_name': 'Вася', 'mother_name': 'Галя', 'father_name': 'Вася', 'pet_name': 'Вася'}

counter_student_name_max[name] += 1
else:
counter_student_name_max[name] = 1
name = sorted(counter_student_name_max.items(), key=lambda item: item[1], reverse=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как вариант, ещё можно использовать max(), он тоже умеет с аргументом key

]
# ???

def max_count_name(arg, arg2):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def max_count_name(arg, arg2):
def max_count_name(school_class, number_class):



number_class = 0
for school_class in school_students:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for school_class in school_students:
for number_class, school_class in enumerate(school_students):

counter_student_name_max[name] = 1
name_student = sorted(counter_student_name_max.items(), key=lambda item: item[1], reverse=True)

return f'Самое частое имя в классе {arg2}: {name_student[0][0]}'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще это законно, но я бы предложил возвращать просто name_student[0][0], а весь пост-процессинг делать за пределами функции. Таким образом мы немножко улучшим чистоту кода.

number_class = 0
for school_class in school_students:
number_class += 1
print(max_count_name(school_class, number_class))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(max_count_name(school_class, number_class))
most_frequent_name = max_count_name(school_class)
print(f'Самое частое имя в классе {number_class}: {most_frequent_name }')



for classes in school:
for key, value in classes.items():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ага, здесь тоже просто по ключу берём из словаря то, что надо, цикл не нужен

}
# ???

def student_counting(val, numb):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def student_counting(val, numb):
def student_counting(students, class_num):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants